package web

import (
	"ebip/internel/types"
	"ebip/internel/web/handler"
	wp "ebip/pkg/ginl/wrap_gin"
	"github.com/gin-gonic/gin"
)

// @Description
// @Author 代码小学生王木木

type Router struct {
	codeHdl *handler.CodeHandler
	authHdl *handler.AuthHandler
	userHdl *handler.UserHandler
	fileHdl *handler.FileHandler
	entHdl  *handler.EnterpriseHandler
}

func NewRouter(codeHdl *handler.CodeHandler, authHdl *handler.AuthHandler, userHdl *handler.UserHandler, fileHdl *handler.FileHandler, entHdl *handler.EnterpriseHandler) *Router {
	return &Router{
		codeHdl: codeHdl,
		authHdl: authHdl,
		userHdl: userHdl,
		fileHdl: fileHdl,
		entHdl:  entHdl,
	}
}

func (r Router) RegisterRouter(engine *gin.Engine) {
	engine.GET("/code", wp.Wrap(r.codeHdl.ImageCaptcha)) // 获取图片验证码
	engine.POST("/pwd-login", wp.WrapJson[types.PwdLoginReq](r.authHdl.PwdLogin))
	engine.POST("/logout", wp.WrapToken[types.UserClaims](r.authHdl.LogoutUser))
	engine.GET("/default-admin", wp.Wrap(r.userHdl.GenDefaultUser))
	//engine.GET("/user/info", wp.WrapToken[types.UserClaims](r.userHdl.GetUserInfo))
	engine.GET("/user/info", wp.Wrap(r.userHdl.GetUserInfo))

	//epRouter := engine.Group("/companies")
	//{
	//	epRouter.GET("/list") // 搜索分页用于展示企业信息列表
	//}

	fileRouter := engine.Group("/file")
	{
		fileRouter.POST("/upload", wp.Wrap(r.fileHdl.Upload))
	}

	adminEntRoute := engine.Group("/admin")
	{
		adminEntRoute.GET("/ent/list", wp.Wrap(r.entHdl.AdminSearchList))
		adminEntRoute.POST("/ent/parser-v1", wp.WrapJson[types.ParseExcelRequest](r.entHdl.ParseEnterpriseSync))
		adminEntRoute.POST("/ent/parser-v2", wp.WrapJson[types.ParseExcelRequest](r.entHdl.ParseEnterpriseAsync))
	}
}
